<!--
***我的潮货***
-->
<template>
  <div>
    <v-header>
      <div class="nav-tab2">
        <h3>我的</h3>
      </div>
    </v-header>
    <div class="notice" v-if="noticeList&&noticeList.length>0">
      <ul ref="noticeul" :style="css.cssTop">
        <li v-for="(item, index) in noticeList" class="ellipsis" :key="index" style="position:relative;top:1px;">{{item}}</li>
      </ul>
    </div>

    <div class="income" v-if="incomeData">
      <p class="income-tiele">可提现金额</p>
      <div class="withdraw">
        <p class="withdraw-amount font-price">{{incomeData.canbemoney.toFixed(2)}}</p>
        <span class="withdraw-buttom child-center" @click="withdraw">提现</span>
      </div>
      <div class="income-details">
        <div class="total-income child-center" @click="goOrderDetails(1)">
          <p class="income-details-title">累计收入</p>
          <p class="income-details-num">¥{{incomeData.histroyincome.toFixed(2)}}</p>
        </div>
        <div class="expected-income child-center" @click="goOrderDetails(2)">
          <p class="income-details-title">本月预估收入</p>
          <p class="income-details-num">¥{{incomeData.thismonthincome.toFixed(2)}}</p>
        </div>
        <div class="before-income child-center" @click="goOrderDetails(3)">
          <p class="income-details-title">上月收入</p>
          <p class="income-details-num">¥{{incomeData.incomelastmonth.toFixed(2)}}</p>
        </div>
      </div>
    </div>

    <div class="my-agents" @click="goMyDistributor" v-if="beeData">
      <div class="my-agents-top">
        <span>我的买手</span>
        <span v-if="beeData.weekincre">近7日新增{{beeData.weekincre}}人 <img src="/static/img/right_arrow.png" style="width:3.33vw" /></span>
        <span v-else><img src="/static/img/right_arrow.png" style="width:3.33vw" /></span>
      </div>
      <div class="my-agents-info">
        <div class="my-agents-info-item">
          <p class="my-agents-info-num">{{beeData.peoplenum}}</p>
          <p class="my-agents-info-title">总人数</p>
        </div>
        <div class="my-agents-info-item">
          <p class="my-agents-info-num">{{beeData.ordernum}}</p>
          <p class="my-agents-info-title">订单数量</p>
        </div>
        <div class="my-agents-info-item">
          <p class="my-agents-info-num">{{beeData.histroymoney.toFixed(2)}}</p>
          <p class="my-agents-info-title">总金额(元)</p>
        </div>
      </div>
    </div>

    <img mode="widthFix"  src='//files.eyee.com/mcdn/img/dis-share-bee.png' style='width:90vw;box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.1);margin:20px auto;display:block;' @click="goMyDistributor"  />

    <div class="latest-orders" v-if="orderData">
      <div class="latest-orders-top">
        <span>最新订单</span>
        <span tag="span" @click="goOrderDetails(4)">全部订单</span>
      </div>
      <div class="latest-orders-content">
        <p class="latest-orders-name">
          <span class="ellipsis">{{orderData.list[0].title||'推荐好友成为买手奖励'}}</span><span>+{{orderData.list[0].withdraw}}</span>
        </p>
        <div class="latest-orders-info">
          <p class="latest-orders-detailed">
            <span>{{orderData.list[0].confirmtime}}</span>
            <span>金额：¥{{orderData.list[0].paymoney}}</span>
          </p>
          <p>{{orderStatus[orderData.list[0].status]}}</p>
        </div>
      </div>
    </div>

    <div class="distribution-commodity">
      <p class="distribution-commodity-top">
        <span style="border-left: 2px solid #000;padding-left: 10px;height:14px;line-height: 14px;">我的图文（{{graphicNum}}）</span>
        <span class="distribution-commodity-all" @click="goMyCommodity">查看全部 ></span>
      </p>
    </div>
    <distribution-empty :showType="0" v-if="!graphicData"></distribution-empty>
    <div class="commodity-list">
      <distribution-commodity-unit v-for="item in graphicData" :key='item.id' class="commodity-unit" :commodityInfo='item'></distribution-commodity-unit>
      <!--<a href="javascript:;" @click="goMyCommodity" class="commodity-more">查看更多</a>-->
    </div>
    <div class="distribution-help" @click="gotoHelp">
      <span>帮助中心</span>
      <em></em>
    </div>
    <p class="bottom-tips">别再拉了，已经到底辣~</p>
    <Menu :position="menu" v-if="!$root.ISAPP"></Menu>
    <mt-popup v-model="css.popup">
      <div class="popup" v-if="incomeData">
        <div class="close" @click="close"></div>
        <div class="download" v-if="incomeData.canbemoney>200">
          <p>您的可提现金额为：<span>¥{{incomeData.canbemoney}}</span></p>
          <p>为了更好的提现体验，请下载APP哦~</p>
          <div class="btn" @click="downloadApp">下载APP</div>
        </div>
        <div class="notW" v-else>
          <div class="title">不可提现说明</div>
          <p class="text">抱歉，您的可提现金额不足200元，请先分享好友赚取更多佣金再来提现吧~ </p>
          <p class="tips">如有疑问请在”斗牛”APP,联系客服小姐姐哦~ </p>
        </div>
      </div>
    </mt-popup>
  </div>
</template>
<script>
import { getUrlParam } from '@/common/util'
import distributionCommodityUnit from './DistributionCommodityUnit'
import DistributionEmpty from './DistributionEmpty'
import Menu from './Menu'
import { getIncomeInfo, getNewOrder, getMybee, getMyGraphic, message, shareToBeDistributionUrl } from '../../common/api/distribution'
export default {
  components: {
    'distribution-commodity-unit': distributionCommodityUnit,
    DistributionEmpty,
    Menu
  },
  data() {
    return {
      menu: 'myDistribution',
      css: {
        popup: false,
        cssTop: {
          top: 0
        }
      },
      noticeList: [],
      incomeData: '',
      orderData: '',
      beeData: '',
      graphicData: '',
      graphicNum: 0,
      distributionId: window.localStorage.getItem('distributionId'),
      orderStatus: ['已付款', '已收货', '售后退款', '已结算']
    }
  },
  created() {
    if (this.$root.ISAPP) {
      let param = getUrlParam('param')

      let tempParam = null
      try {
        tempParam = JSON.parse(decodeURIComponent(param))
      } catch (e) {
        console.log('JSON parse error: ', e)
      }

      this.distributionId = tempParam.distributionId
      console.log('currentUser: ', tempParam)
    } else {
      if (!JSON.parse(window.localStorage.getItem('currentUser') || '{}').token) {
        this.$router.push(`/login`)
      }
    }

    this.getIncome()
    this.getGraphic()
    message({ distributionid: this.distributionId }).then(res => {
      if (res && res.length > 0) {
        this.noticeList = res.map(item => {
          if (item.type === 0) {
            item.pmobile = this.blurPhone(item.pmobile)
            item.umobile = this.blurPhone(item.umobile)
            return `${item.pmobile || '用户xx'} 邀请 ${item.umobile || '用户xx'} 成为买手`
          } else if (item.type === 1) {
            item.pmobile = this.blurPhone(item.pmobile)
            return `${item.pmobile || '用户xx'} 获得 ¥${item.withdraw || 10} 佣金收入`
          } else {
            item.umobile = this.blurPhone(item.umobile)
            return `${item.umobile || '用户xx'} 注册成为分销商`
          }
        })
        this.$nextTick(() => { this.notice() })
      }
    })

    shareToBeDistributionUrl({
      parentid: this.distributionId
    }).then(res=>{
      if (this.$root.ISAPP) {
        let opt = {
          name: 'getAppActivityShareContent',
          params: {
            sharetitle: res.shareinfo.title,
            sharecontent: res.shareinfo.content,
            sharepicurl: res.shareinfo.icon,
            shareurl: res.shareinfo.url,
            xcxurl: res.shareinfo.scene,
          }
        }
        this.javascriptBridge(opt)
      }else{
        this.initShare({
          info:{
            title:res.shareinfo.title,
            desc:res.shareinfo.content,
            img:res.shareinfo.icon,
            url:res.shareinfo.url
          }
        })
      }
    })
  },
  methods: {
    goOrderDetails(type) {
      this.$router.push(`/distribution/orderDetailed/${type}`)
    },
    goMyCommodity() {
      this.$router.push('/distribution/myCommodity')
    },
    goMyDistributor() {
      this.$router.push('/distribution/myDistributor')
    },
    gotoHelp() {
      this.$router.push('/distribution/help')
    },
    withdraw() {
      this.css.popup = true
    },
    close() {
      this.css.popup = false
    },
    downloadApp() {
      this.close()
      this.loadApp()
    },
    getIncome() {
      let opt = {
        distributionid: this.distributionId
      }
      getIncomeInfo(opt)
        .then(res => {
          this.incomeData = res
        })
      getNewOrder(opt)
        .then(res => {
          if (res && res.list.length > 0) {
            this.orderData = res
          }
        })
      getMybee(opt)
        .then(res => {
          this.beeData = res
        })
    },
    getGraphic() {
      let opt = {
        distributionid: this.distributionId,
        status: 3,
        page: 1,
        size: 3
      }
      getMyGraphic(opt)
        .then(res => {
          if (res && res.list.length > 0) {
            this.graphicData = res.list
            this.graphicNum = res.total
          }
        })
    },
    notice() {
      var Ttime = null
      var TOPval = 0
      var _ = this
      let Height = this.$refs.noticeul.getBoundingClientRect().height
      clearInterval(Ttime)
      Ttime = setInterval(() => {
        TOPval += Height
        _.css.cssTop.top = -TOPval + 'px'
        if (TOPval > Height * (_.noticeList.length - 1)) {
          _.css.cssTop.top = 0
          TOPval = 0
        }
      }, 3000)
    },

    blurPhone(phone) {
      phone = phone.replace('+86-','')
      return phone.substr(0, 3) + '*****' + phone.substr(8)
    }
  }
}
</script>

<style lang='scss' scoped>
.notice {
  width: 100%;
  height: 24px;
  background-color: rgb(126, 107, 37);
  font-size: 14px;
  line-height: 24px;
  color: #fff;
  padding: 0 4vw;
  position: relative;
  overflow: hidden;
  &::before{
    content: '';
    width: 14px;
    height: 14px;
    float: left;
    background: url(/static/img/d_notice.png);
    background-size: 14px 14px;
    margin: 5px 5px 0 0;
  }
  ul{
    height: 24px;
    position: absolute;
    transition: all .1s linear;
    top: 0;
    left: 35px;
  }
}
.income {
  height: 190px;
  width: 100%;
  background-color: rgb(51, 51, 51);
  color: #fff;
  overflow: hidden;
}
.income-tiele {
  font-size: 12px;
  margin-top: 20px;
  padding-left: 5.33vw;
}
.withdraw {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
  line-height: 1;
  padding: 0 5.33vw;
}
.withdraw-amount {
  font-size: 33px;
}
.child-center {
  display: flex;
  justify-content: center;
  align-items: center;
}
.withdraw-buttom {
  width: 66px;
  height: 26px;
  border-radius: 4px;
  font-size: 17px;
  background: #FFC700;
  color: #fff;
  line-height: 26px;
}
.income-details {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 20px;
}
.income-details > div {
  flex-direction: column;
  flex: 1;
  text-align: center;
}
.total-income .income-details-title {
  font-size: 13px;
}
.income-details-title {
  font-size: 13px;
  font-weight: 300;
  color: rgba(255, 255, 255, .5);
  margin-bottom: 5px;
}
.expected-income {
  border-left: 1px solid rgba(255, 255, 255, .5);
  border-right: 1px solid rgba(255, 255, 255, .5);
  padding: 5px 0;
}

.my-agents {
  width: 89.33vw;
  height: 32vw;
  box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.1);
  margin: -27px auto 0;
  background-color: #fff;
  border-radius: 5px;
}

.my-agents-top,
.latest-orders-top {
  margin: 1.6vw 2.67vw 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgb(245, 245, 245);
}
.my-agents-top > span,
.latest-orders-top > span {
  padding: 1.6vw 0;
  display: flex;
  align-items: center;
  font-size: 3.2vw;
  color: rgb(153, 153, 153);
}
.my-agents-top > span:first-of-type,
.latest-orders-top > span:first-of-type{
  color: #333;
}
.my-agents-info {
  display: flex;
  align-items: center;
  height: 23.2vw;
  width: 100%;
}
.my-agents-info-item {
  width: 32vw;
  height: 16.8vw;
  border-right: 1px solid rgb(245, 245, 245);
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2vw 0;
}
.my-agents-info-num {
  font-size: 16px;
  color: rgb(51, 51, 51);
  margin-bottom: 5px;
  font-weight: 600;
}
.my-agents-info-title,
.my-agents-share {
  font-size: 12px;
  color: rgb(102, 102, 102);
}
.my-agents-share {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 4.8vw;
  img{
    width: 23px;
    margin-bottom: 2px;
  }
  p{
    text-align: center;
  }
}

.latest-orders {
  width: 92vw;
  height: 27.2vw;
  box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.1);
  margin: 5.6vw auto 0;
  background-color: #fff;
  border-radius: 5px;
}
.latest-orders-name {
  font-size: 12px;
  color: rgb(51, 51, 51);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 3.2vw 2.4vw 0;
}
.latest-orders-info {
  font-size: 10px;
  color: rgb(102, 102, 102);
  padding: 2.4vw 2.4vw 0;
  display: flex;
  justify-content: space-between;
}
.latest-orders-detailed span {
  padding-right: 2vw;
}
.distribution-commodity {
  width: 92vw;
  margin: 5.6vw auto;
}
.distribution-commodity-top {
  display: flex;
  justify-content: space-between;
  color: rgb(51, 51, 51);
  font-size: 12px;
  align-items: center;
}
.distribution-commodity-top span{
  font-size: 14px;
  font-weight: bold;
}
.distribution-commodity-top .distribution-commodity-all {
  color: rgb(153, 153, 153);
  font-size: 10px;
  font-weight: normal;
}
.commodity-list{
  width: 94.67vw;
  margin: 4vw auto;
}
.commodity-unit{
  margin-top: 4vw;
}
.distribution-help{
  margin: 0 2.67vw;
  box-shadow:0px 3px 7px 0px rgba(0,0,0,0.1);
  font-size: 14px;
  border-radius:8px;
  line-height: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 15px;
  span{
    &::before{
      content: '';
      width: 14px;
      height: 17px;
      background: url(/static/img/d_icon_help.png);
      background-size: 14px 17px;
      float: left;
      margin: 13px 10px 0 0;
    }
  }
  em{
    border-right: 1px solid #999;
    border-bottom: 1px solid #999;
    transform-origin: 50% 50%;
    transform: rotate(-45deg);
    width: 10px;
    height: 10px;
  }
}
.bottom-tips{
  font-size: 12px;
  color: #999;
  margin: 5vw 0 6vw;
  display: flex;
  justify-content: center;
}
.commodity-more{
  font-size: 12px;
  display: block;
  margin: 4vw auto 0;
  width: 20vw;
  &::after{
    content: '';
    background: url(/static/img/d_more.png);
    display: inline-block;
    background-size: 14px 14px;
    width: 14px;
    height: 14px;
    position: relative;
    top: 2px;
  }
}
.mint-popup{
  background: none;
}
.popup{
  width: 88vw;
  height: 62vw;
  border-radius: 8px;
  background: url(/static/img/d_popup.png) right bottom #fff;
  background-size: 335px 233px;
  position: relative;
  display: flex;
  .download{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 100%;
    padding-top: 20vw;
    p{
      text-align: center;
      font-size: 14px;
      span{
        color: #FFC700;
        font-size: 18px;
      }
    }
    .btn{
      height: 10.67vw;
      text-align: center;
      background: #333;
      color: #fff;
      line-height: 10.67vw;
      border-radius: 0 0 8px 8px;
      margin-top: 10vw;
    }
  }
  .notW{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0 5.33vw;
    .title{
      font-size: 16px;
      font-weight: bold;
      text-align: center;
      padding-top: 10vw;
    }
    .text{
      font-size: 14px;
    }
    .tips{
      font-size: 12px;
      color: #999;
      line-height: 16vw;
      border-top: 1px dashed #ccc;
    }
  }
  .close{
    width: 7vw;
    height: 7vw;
    position: absolute;
    right: 3vw;
    top: 3vw;
    z-index: 10;
    &::before{
      content: '';
      width: 100%;
      height: 1px;
      background: #333;
      position: absolute;
      transform-origin: 50% 0;
      transform: rotate(45deg);
      position: absolute;
      top: 3vw;
    }
    &::after{
      content: '';
      width: 100%;
      height: 1px;
      background: #333;
      position: absolute;
      transform-origin: 50% 0;
      transform: rotate(-45deg);
      position: absolute;
      top: 3vw;
    }
  }
}
</style>
